package com.handtransaction.controller;

import com.handtransaction.entity.Goods;
import com.handtransaction.entity.TOGoods;
import com.handtransaction.service.GoodsService;
import com.handtransaction.service.TipOffService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
public class TipOffGoodsController {
    @Autowired
    TipOffService tipOffService;
    @Autowired
    GoodsService goodsService;

    //管理员查看所有被举报商品记录
    @RequestMapping("/showAllTOGoods")
    public String showAllTOGoods(Model model){
        List<TOGoods> list = tipOffService.showAllTOGoods();
        model.addAttribute("TOGoodsList",list);
        return "admin/tipOff/adminAllGoodsTipOff";
    }

    //用户编写商品举报理由
    @RequestMapping("/writeTOGoods")
    public String writeTOGoods(Integer gid , Model model){
        Goods good = goodsService.QueryGoodBygid(gid);
        model.addAttribute("good",good);
        return "tipOff/writeTOGoods";
    }

    //用户提交生成商品举报
    @RequestMapping("/createTOGoods")
    public String createTOGoods(TOGoods toGoods, Model model){
        tipOffService.createTOGood(toGoods);
        return "redirect:ShowALLGoods";
    }

    //管理员通过举报信息来下架商品
    @RequestMapping("/offShelfTOGoods")
    public String offShelfTOGoods(Integer gid , Model model){
        tipOffService.deleteOffShelfTOGoods(gid);
        model.addAttribute("gid",gid);
            // 待解答疑惑：model中加入键值对（reason，“管理员下架”），转发后另一个控制器接收不到，为null
            // model.addAttribute("reason" , "管理员下架举报商品")
        return "forward:/offShelfTipOffGoods";
    }

    //管理员驳回该无效举报
    @RequestMapping("/ignoreTOGoods")
    public String ignoreTOGoods(Integer tid){
        tipOffService.deleteTOGood(tid);
        return "redirect:/showAllTOGoods";
    }



}
